package dianmobile.eistarandroid.ui.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;

import dianmobile.eistarandroid.R;
import dianmobile.eistarandroid.beans.MyArticleEntity;

/**
 * Created by Administrator on 2015/7/9.
 */
public class MyArticleListAdapter extends BaseAdapter {

    private final String TAG = getClass().getSimpleName();
    private List<MyArticleEntity> myArticleListData;
    private LayoutInflater mInflater;

    public MyArticleListAdapter(Context context, List<MyArticleEntity> listData) {
        this.myArticleListData = listData;
        mInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return myArticleListData.size();
    }

    @Override
    public Object getItem(int position) {
        return myArticleListData.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        //TODO 判断空值
        if (myArticleListData.isEmpty()) {
            return null;
        }

        final MyArticleEntity item = myArticleListData.get(position);

        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.listitem_my_article, null);

            viewHolder = new ViewHolder();
            viewHolder.tvBoardName = (TextView)convertView.findViewById(R.id.tv_board_of_my_article);
            viewHolder.tvArticleTitle = (TextView)convertView.findViewById(R.id.tv_title_of_my_article);
            viewHolder.tvPostTime = (TextView)convertView.findViewById(R.id.tv_time_of_my_article);

            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder)convertView.getTag();
        }

        viewHolder.tvBoardName.setText(item.getBoardName());
        viewHolder.tvArticleTitle.setText(item.getArticleTitle());
        viewHolder.tvPostTime.setText(item.getPostTime());

        return convertView;
    }

    static class ViewHolder {
        public TextView tvBoardName;
        public TextView tvPostTime;
        public TextView tvArticleTitle;
    }
}
